home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / sptmbr16.lha / new-kcl-wrapper.text < prev    next >
Text File  |  1992-07-06  |  60KB  |  2,158 lines

  1. The new-kcl-wrapper modifications make the storage of standard-objects
  2. and structure objects much more similar than before.  These changes should 
  3. greatly speed up WRAPPER-OF for structure objects and should speed up
  4. WRAPPER-OF for standard-instances also (but not funcallable instances).
  5.  
  6. Look first at the defstructs defined here (scan this file for "(defstruct (").
  7. Then look at cache.lisp, at the "#+structure-wrapper" for the new definition of
  8. the wrapper structure.  Finally, look in low.lisp, at the 
  9. "#+new-structure-wrapper" for the definition of %allocate-instance--class.
  10.  
  11. You need to have akcl-1-615 to use this file.
  12.  
  13. This file contains new versions of the files V/c/structure.c and 
  14. V/lsp/defstruct.lsp, as well as small changes to the files c/gbc.c, c/sgbc.c, 
  15. cmpnew/cmpinit.lsp, lsp/cmpinit.lsp, and lsp/describe.lsp.
  16.  
  17. -- The gbc changes allow the garbage collector to work correctly even when
  18. structures which define other structures (ones which can be the value of 
  19. STRUCTURE-DEF) are not allocated in static storage. 
  20.  
  21.  
  22. c/gbc.c
  23. *** c/gbc.c       Tue Jun 30 04:11:00 1992
  24. --- ../akcl-1-615/c/gbc.c Tue Jun 30 02:48:04 1992
  25. ***************
  26. *** 427,453 ****
  27.                           break;
  28.                   goto COPY_STRING;
  29.   
  30.           case t_structure:
  31.                   mark_object(x->str.str_def);
  32.                   p = x->str.str_self;
  33.                   if (p == NULL)
  34. !                         break;
  35. !                 {object def=x->str.str_def;
  36. !                  unsigned char * s_type = &SLOT_TYPE(def,0);
  37. !                  unsigned short *s_pos= & SLOT_POS(def,0);
  38. !                  for (i = 0, j = S_DATA(def)->length;  i < j;  i++)
  39.                      if (s_type[i]==0) mark_object(STREF(object,x,s_pos[i]));
  40.                    if ((int)what_to_collect >= (int)t_contiguous) {
  41.                        if (inheap(x->str.str_self)) {
  42.                          if (what_to_collect == t_contiguous)
  43.                            mark_contblock((char *)p,
  44. !                                         S_DATA(def)->size);
  45.   
  46.                        } else
  47. !                        x->str.str_self = (object *)
  48. !                          copy_relblock((char *)p, S_DATA(def)->size);
  49.                      }}
  50.                   break;
  51.   
  52.           case t_stream:
  53.                   switch (x->sm.sm_mode) {
  54. --- 427,461 ----
  55.                           break;
  56.                   goto COPY_STRING;
  57.   
  58.           case t_structure:
  59. +                 x->d.m = 2; 
  60.                   mark_object(x->str.str_def);
  61.                   p = x->str.str_self;
  62.                   if (p == NULL)
  63. !                         {x->d.m = TRUE; break;}
  64. !                 {object def=x->str.str_def;
  65. !                  struct s_data *sdef=S_DATA(def);
  66. !                  unsigned char *s_type;
  67. !                  unsigned short *s_pos;
  68. !                  if((int)what_to_collect >= (int)t_contiguous &&
  69. !                     !inheap(sdef) && def->d.m==TRUE)
  70. !                    sdef=(struct s_data *)(((char *)sdef)+(rb_start1-rb_start));
  71. !                  s_type = sdef->raw->ust.ust_self;
  72. !                  s_pos = &USHORT(sdef->slot_position,0);
  73. !                  for (i = 0, j = sdef->length;  i < j;  i++)
  74.                      if (s_type[i]==0) mark_object(STREF(object,x,s_pos[i]));
  75.                    if ((int)what_to_collect >= (int)t_contiguous) {
  76.                        if (inheap(x->str.str_self)) {
  77.                          if (what_to_collect == t_contiguous)
  78.                            mark_contblock((char *)p,
  79. !                                         sdef->size);
  80.   
  81.                        } else
  82. !                         x->str.str_self = (object *)
  83. !                          copy_relblock((char *)p, sdef->size);
  84.                      }}
  85. +                 x->d.m = TRUE; 
  86.                   break;
  87.   
  88.           case t_stream:
  89.                   switch (x->sm.sm_mode) {
  90. *** c/sgbc.c      Mon Jun 15 21:16:01 1992
  91. --- akcl-1-615/c/sgbc.c   Wed Jul  1 18:37:24 1992
  92. ***************
  93. *** 355,386 ****
  94.                   if (cp == NULL)
  95.                           break;
  96.                   goto COPY_STRING;
  97.   
  98.           case t_structure:
  99.                   sgc_mark_object(x->str.str_def);
  100.                   p = x->str.str_self;
  101.                   if (p == NULL)
  102. !                         break;
  103. !                 {object def=x->str.str_def;
  104. !                  unsigned char * s_type = &SLOT_TYPE(def,0);
  105. !                  unsigned short *s_pos= & SLOT_POS(def,0);
  106. !                  for (i = 0, j = S_DATA(def)->length;  i < j;  i++)
  107.                      if (s_type[i]==0 &&
  108.                          ON_WRITABLE_PAGE(& STREF(object,x,s_pos[i]))
  109.                          )
  110.                        sgc_mark_object(STREF(object,x,s_pos[i]));
  111.                    if ((int)what_to_collect >= (int)t_contiguous) {
  112.                        if (inheap(x->str.str_self)) {
  113.                          if (what_to_collect == t_contiguous)
  114.                            mark_contblock((char *)p,
  115. !                                         S_DATA(def)->size);
  116.   
  117.                        } else if(SGC_RELBLOCK_P(p))
  118.                          x->str.str_self = (object *)
  119. !                          copy_relblock((char *)p, S_DATA(def)->size);
  120.                      }}
  121.                   break;
  122.   
  123.           case t_stream:
  124.                   switch (x->sm.sm_mode) {
  125.                   case smm_input:
  126. --- 355,394 ----
  127.                   if (cp == NULL)
  128.                           break;
  129.                   goto COPY_STRING;
  130.   
  131.           case t_structure:
  132. +                 x->d.m = 2;
  133.                   sgc_mark_object(x->str.str_def);
  134.                   p = x->str.str_self;
  135.                   if (p == NULL)
  136. !                         {x->d.m = TRUE; break;}
  137. !                 {object def=x->str.str_def;
  138. !                  struct s_data *sdef=S_DATA(def);
  139. !                  unsigned char *s_type;
  140. !                  unsigned short *s_pos;
  141. !                  if((int)what_to_collect >= (int)t_contiguous &&
  142. !                     !inheap(sdef) && def->d.m==TRUE)
  143. !                    sdef=(struct s_data *)(((char *)sdef)+(rb_start1-rb_start));
  144. !                  s_type = sdef->raw->ust.ust_self;
  145. !                  s_pos = &USHORT(sdef->slot_position,0);
  146. !                  for (i = 0, j = sdef->length;  i < j;  i++)
  147.                      if (s_type[i]==0 &&
  148.                          ON_WRITABLE_PAGE(& STREF(object,x,s_pos[i]))
  149.                          )
  150.                        sgc_mark_object(STREF(object,x,s_pos[i]));
  151.                    if ((int)what_to_collect >= (int)t_contiguous) {
  152.                        if (inheap(x->str.str_self)) {
  153.                          if (what_to_collect == t_contiguous)
  154.                            mark_contblock((char *)p,
  155. !                                         sdef->size);
  156.   
  157.                        } else if(SGC_RELBLOCK_P(p))
  158.                          x->str.str_self = (object *)
  159. !                          copy_relblock((char *)p, sdef->size);
  160.                      }}
  161. +                 x->d.m = TRUE; 
  162.                   break;
  163.   
  164.           case t_stream:
  165.                   switch (x->sm.sm_mode) {
  166.                   case smm_input:
  167. cmpnew/cmpinit.lsp
  168. *** cmpnew/cmpinit.lsp    Tue Jun 30 04:11:13 1992
  169. --- ../akcl-1-615/cmpnew/cmpinit.lsp      Mon Jun 22 18:41:51 1992
  170. ***************
  171. *** 4,7 ****
  172. --- 4,10 ----
  173.   (load "sys-proclaim.lisp")
  174.   (setq compiler::*eval-when-defaults* '(compile eval load))
  175.   
  176.   ;(dolist (v '( cmpeval cmpopt cmptype cmpbind cmpinline cmploc cmpvar cmptop cmplet cmpcall cmpmulti cmplam cmplabel          cmpeval))   (load (format nil "~(~a~).lsp" v)))
  177. + (unless (get 'si::basic-wrapper 'si::s-data)
  178. +   (setf (get 'si::s-data 'si::s-data) nil)
  179. +   (load "../lsp/defstruct.lsp"))
  180. lsp/cmpinit.lsp
  181. *** lsp/cmpinit.lsp       Tue Jun 30 04:11:26 1992
  182. --- ../akcl-1-615/lsp/cmpinit.lsp Mon Jun 22 17:11:11 1992
  183. ***************
  184. *** 5,12 ****
  185.   (or (fboundp 'si::get-&environment) (load "defmacro.lsp"))
  186.   ;(or (get 'si::s-data 'si::s-data)
  187.   ;    (progn (load "../lsp/setf.lsp") (load "../lsp/defstruct.lsp")))
  188.   (if (probe-file "sys-proclaim.lisp")(load "sys-proclaim.lisp"))
  189.   
  190.   ;;;;;
  191. --- 5,13 ----
  192.   (or (fboundp 'si::get-&environment) (load "defmacro.lsp"))
  193.   ;(or (get 'si::s-data 'si::s-data)
  194.   ;    (progn (load "../lsp/setf.lsp") (load "../lsp/defstruct.lsp")))
  195.   (if (probe-file "sys-proclaim.lisp")(load "sys-proclaim.lisp"))
  196. ! (unless (get 'si::basic-wrapper 'si::s-data)
  197. !   (setf (get 'si::s-data 'si::s-data) nil)
  198. !   (load "../lsp/defstruct.lsp"))
  199.   
  200.   ;;;;;
  201. lsp/describe.lsp
  202. *** lsp/describe.lsp      Tue Jun 30 04:11:27 1992
  203. --- ../akcl-1-615/lsp/describe.lsp        Tue Jun 23 16:39:07 1992
  204. ***************
  205. *** 266,282 ****
  206.   
  207.   (defun inspect-structure (x &aux name)
  208.     (format t "Structure of type ~a ~%Byte:[Slot Type]Slot Name   :Slot Value"
  209.             (setq name (type-of x)))
  210. !   (let* ((sd (get name 'si::s-data))
  211.            (spos (s-data-slot-position sd)))
  212.       (dolist (v (s-data-slot-descriptions sd))
  213.               (format t "~%~4d:~@[[~s] ~]~20a:~s"   
  214. !                     (aref spos (nth 4 v))
  215. !                     (let ((type (nth 2 v)))
  216.                         (if (eq t type) nil type))
  217. !                     (car v)
  218. !                     (structure-ref1 x (nth 4 v))))))
  219.       
  220.     
  221.   (defun inspect-object (object &aux (*inspect-level* *inspect-level*))
  222.     (inspect-indent)
  223. --- 266,282 ----
  224.   
  225.   (defun inspect-structure (x &aux name)
  226.     (format t "Structure of type ~a ~%Byte:[Slot Type]Slot Name   :Slot Value"
  227.             (setq name (type-of x)))
  228. !   (let* ((sd (structure-def x))
  229.            (spos (s-data-slot-position sd)))
  230.       (dolist (v (s-data-slot-descriptions sd))
  231.               (format t "~%~4d:~@[[~s] ~]~20a:~s"   
  232. !                     (aref spos (slot-offset v))
  233. !                     (let ((type (slot-type v)))
  234.                         (if (eq t type) nil type))
  235. !                     (slot-name v)
  236. !                     (structure-ref1 x (slot-offset v))))))
  237.       
  238.     
  239.   (defun inspect-object (object &aux (*inspect-level* *inspect-level*))
  240.     (inspect-indent)
  241. ==============================================================================
  242. =============================== c/structure.c ================================
  243. Changes file for /kcl/c/structure.c
  244. Usage \n@s[Original text\n@s|Replacement Text\n@s]
  245. See the file rascal.ics.utexas.edu:/usr2/ftp/merge.c
  246. for a program to merge change files.  Anything not between
  247.  "\n@s[" and  "\n@s]" is a simply a comment.
  248. This file was constructed using emacs and  merge.el
  249.  by (Bill Schelter)  wfs@carl.ma.utexas.edu 
  250.  
  251.  
  252. ****Change:(orig (15 17 d))
  253. @s[object siSstructure_print_function;
  254. object siSstructure_slot_descriptions;
  255. object siSstructure_include;
  256.  
  257. @s|
  258. @s]
  259.  
  260.  
  261. ****Change:(orig (18 18 a))
  262. @s[
  263.  
  264. @s|
  265. #define COERCE_DEF(x) if (type_of(x)==t_symbol) \
  266.   x=getf(x->s.s_plist,siLs_data,Cnil)
  267.  
  268. #define check_type_structure(x) \
  269.   if(type_of((x))!=t_structure) \
  270.     FEwrong_type_argument(Sstructure,(x)) 
  271.  
  272.  
  273.  
  274. @s]
  275.  
  276.  
  277. ****Change:(orig (22 31 c))
  278. @s[{
  279.     do {
  280.         if (type_of(x) != t_symbol)
  281.                 return(FALSE);
  282.  
  283. @s,       } while (x != Cnil);
  284.     return(FALSE);
  285. }
  286.  
  287. @s|{ if (x==y) return 1;
  288.   if (type_of(x)!= t_structure
  289.       || type_of(y)!=t_structure)
  290.     FEerror("bad call to structure_subtypep",0);
  291.   {if (S_DATA(y)->included == Cnil) return 0;
  292.    while ((x=S_DATA(x)->includes) != Cnil)
  293.      { if (x==y) return 1;}
  294.    return 0;
  295.  }}
  296.  
  297. @s]
  298.  
  299.  
  300. ****Change:(orig (32 32 a))
  301. @s[
  302.  
  303. @s|
  304. static
  305. bad_raw_type()
  306. {           FEerror("Bad raw struct type",0);}
  307.  
  308.  
  309.  
  310. @s]
  311.  
  312.  
  313. ****Change:(orig (34 34 c))
  314. @s[structure_ref(x, name, n)
  315.  
  316. @s|structure_ref(x, name, i)
  317.  
  318. @s]
  319.  
  320.  
  321. ****Change:(orig (36 38 c))
  322. @s[object x, name;
  323. int n;
  324. {
  325.     int i;
  326.  
  327. @s|object x, name;
  328. int i;
  329. {unsigned short *s_pos;
  330.  COERCE_DEF(name);
  331.  if (type_of(x) != t_structure ||
  332.      (type_of(name)!=t_structure) ||
  333.      !structure_subtypep(x->str.str_def, name))
  334.    FEwrong_type_argument((type_of(name)==t_structure ?
  335.                   S_DATA(name)->name : name),
  336.                  x);
  337.  s_pos = &SLOT_POS(x->str.str_def,0);
  338.  switch((SLOT_TYPE(x->str.str_def,i)))
  339.    {
  340.    case aet_object: return(STREF(object,x,s_pos[i]));
  341.    case aet_fix:  return(make_fixnum((STREF(int,x,s_pos[i]))));
  342.    case aet_ch:  return(code_char(STREF(char,x,s_pos[i])));
  343.    case aet_bit:
  344.    case aet_char: return(make_fixnum(STREF(char,x,s_pos[i])));
  345.    case aet_sf: return(make_shortfloat(STREF(shortfloat,x,s_pos[i])));
  346.    case aet_lf: return(make_longfloat(STREF(longfloat,x,s_pos[i])));
  347.    case aet_uchar: return(make_fixnum(STREF(unsigned char,x,s_pos[i])));
  348.    case aet_ushort: return(make_fixnum(STREF(unsigned short,x,s_pos[i])));
  349.    case aet_short: return(make_fixnum(STREF(short,x,s_pos[i])));
  350.    default:
  351.      bad_raw_type();
  352.      return 0;
  353.    }}
  354.  
  355. @s]
  356.  
  357.  
  358. ****Change:(orig (40 43 c))
  359. @s[       if (type_of(x) != t_structure ||
  360.         !structure_subtypep(x->str.str_name, name))
  361.         FEwrong_type_argument(name, x);
  362.     return(x->str.str_self[n]);
  363.  
  364. @s|
  365. void
  366. siLstructure_ref1()
  367. {object x=vs_base[0];
  368.  int n=fix(vs_base[1]);
  369.  object def;
  370.  check_type_structure(x);
  371.  def=x->str.str_def;
  372.  if(n>= S_DATA(def)->length)
  373.    FEerror("Structure ref out of bounds",0);
  374.  vs_base[0]=structure_ref(x,x->str.str_def,n);
  375.  vs_top=vs_base+1;
  376.  
  377. @s]
  378.  
  379.  
  380. ****Change:(orig (45 45 a))
  381. @s[}
  382.  
  383.  
  384. @s|}
  385.  
  386. void
  387. siLstructure_set1()
  388. {object x=vs_base[0];
  389.  int n=fix(vs_base[1]);
  390.  object v=vs_base[2];
  391.  object def;
  392.  check_type_structure(x);
  393.  def=x->str.str_def;
  394.  if(n>= S_DATA(def)->length)
  395.    FEerror("Structure ref out of bounds",0);
  396.  vs_base[0]=structure_set(x,x->str.str_def,n,v);
  397.  vs_top=vs_base+1;
  398. }  
  399.  
  400.  
  401.  
  402. @s]
  403.  
  404.  
  405. ****Change:(orig (47 47 c))
  406. @s[structure_set(x, name, n, v)
  407.  
  408. @s|structure_set(x, name, i, v)
  409.  
  410. @s]
  411.  
  412.  
  413. ****Change:(orig (49 51 c))
  414. @s[object x, name, v;
  415. int n;
  416. {
  417.     int i;
  418.  
  419. @s|object x, name, v;
  420. int i;
  421. {unsigned short *s_pos;
  422.  
  423.  COERCE_DEF(name);
  424.  if (type_of(x) != t_structure ||
  425.      type_of(name) != t_structure ||
  426.      !structure_subtypep(x->str.str_def, name))
  427.    FEwrong_type_argument((type_of(name)==t_structure ?
  428.                   S_DATA(name)->name : name)
  429.                  , x);
  430.  
  431. @s]
  432.  
  433.  
  434. ****Change:(orig (53 57 c))
  435. @s[       if (type_of(x) != t_structure ||
  436.         !structure_subtypep(x->str.str_name, name))
  437.         FEwrong_type_argument(name, x);
  438.     x->str.str_self[n] = v;
  439.  
  440. @s,       return(v);
  441.  
  442. @s|#ifdef SGC
  443.  /* make sure the structure header is on a writable page */
  444.  if (x->d.m) FEerror("bad gc field",0); else  x->d.m = 0;
  445. #endif   
  446.  
  447.  s_pos= & SLOT_POS(x->str.str_def,0);
  448.  switch(SLOT_TYPE(x->str.str_def,i)){
  449.    
  450.    case aet_object: STREF(object,x,s_pos[i])=v; break;
  451.    case aet_fix:  (STREF(int,x,s_pos[i]))=fix(v); break;
  452.    case aet_ch:  STREF(char,x,s_pos[i])=char_code(v); break;
  453.    case aet_bit:
  454.    case aet_char: STREF(char,x,s_pos[i])=fix(v); break;
  455.    case aet_sf: STREF(shortfloat,x,s_pos[i])=sf(v); break;
  456.    case aet_lf: STREF(longfloat,x,s_pos[i])=lf(v); break;
  457.    case aet_uchar: STREF(unsigned char,x,s_pos[i])=fix(v); break;
  458.    case aet_ushort: STREF(unsigned short,x,s_pos[i])=fix(v); break;
  459.    case aet_short: STREF(short,x,s_pos[i])=fix(v); break;
  460.  default:
  461.    bad_raw_type();
  462.  
  463.    }
  464.  return(v);
  465.  
  466. @s]
  467.  
  468.  
  469. ****Change:(orig (59 59 a))
  470. @s[}
  471.  
  472.  
  473. @s|}
  474.  
  475. void
  476. siLstructure_subtype_p()
  477. {object x,y;
  478.  check_arg(2);
  479.  x=vs_base[0];
  480.  y=vs_base[1];
  481.  if (type_of(x)!=t_structure)
  482.    {vs_base[0]=Cnil; goto BOTTOM;}
  483.  x=x->str.str_def;
  484.  COERCE_DEF(y);
  485.  if (structure_subtypep(x,y)) vs_base[0]=Ct;
  486.  else vs_base[0]=Cnil;
  487.  BOTTOM:
  488.  vs_top=vs_base+1;
  489. }
  490.  
  491. static object
  492. slot_name(x)
  493.      object x;
  494. {
  495.   if(type_of(x)==t_cons)
  496.     return car(x);
  497.   if(type_of(x)==t_structure)
  498.     return x->str.str_self[0];
  499.   return Cnil;
  500. }
  501.  
  502.  
  503. @s]
  504.  
  505.  
  506. ****Change:(orig (64 64 a))
  507. @s[object x;
  508. {
  509.     object *p, s;
  510.  
  511. @s|object x;
  512. {
  513.     object *p, s;
  514.     struct s_data *def=S_DATA(x->str.str_def);
  515.  
  516. @s]
  517.  
  518.  
  519. ****Change:(orig (66 69 c))
  520. @s[
  521.     s = getf(x->str.str_name->s.s_plist,
  522.              siSstructure_slot_descriptions, Cnil);
  523.     vs_push(x->str.str_name);
  524.  
  525. @s|       
  526.     s = def->slot_descriptions;
  527.     vs_push(def->name);
  528.  
  529. @s]
  530.  
  531.  
  532. ****Change:(orig (72 73 c))
  533. @s[       for (i=0, n=x->str.str_length;  !endp(s)&&i<n;  s=s->c.c_cdr, i++) {
  534.         *p = make_cons(car(s->c.c_car), Cnil);
  535.  
  536. @s|       for (i=0, n=def->length;  !endp(s)&&i<n;  s=s->c.c_cdr, i++) {
  537.         *p = make_cons(slot_name(s->c.c_car), Cnil);
  538.  
  539. @s]
  540.  
  541.  
  542. ****Change:(orig (75 75 c))
  543. @s[               *p = make_cons(x->str.str_self[i], Cnil);
  544.  
  545. @s|               *p = make_cons(structure_ref(x,x->str.str_def,i), Cnil);
  546.  
  547. @s]
  548.  
  549.  
  550. ****Change:(orig (81 81 a))
  551. @s[       stack_cons();
  552.     return(vs_pop);
  553. }
  554.  
  555.  
  556. @s|       stack_cons();
  557.     return(vs_pop);
  558. }
  559.  
  560. void
  561.  
  562. @s]
  563.  
  564.  
  565. ****Change:(orig (84 85 c))
  566. @s[       object x;
  567.     int narg, i;
  568.  
  569. @s|  object x,name,*base;
  570.   struct s_data *def;
  571.   int narg, i,size;
  572.   base=vs_base;
  573.   if ((narg = vs_top - base) == 0)
  574.     too_few_arguments();
  575.   x = alloc_object(t_structure);
  576.   name=base[0];
  577.   COERCE_DEF(name);
  578.   if (type_of(name)!=t_structure  ||
  579.       (def=S_DATA(name))->length != --narg)
  580.     FEerror("Bad make_structure args for type ~a",1,
  581.         base[0]);
  582.   x->str.str_def = name;
  583.   x->str.str_self = NULL;
  584.   size=S_DATA(name)->size;
  585.   base[0] = x;
  586.   x->str.str_self = (object *)
  587.     (def->staticp == Cnil ? alloc_relblock(size)
  588.      : alloc_contblock(size));
  589.   /* There may be holes in the structure.
  590.      We want them zero, so that equal can work better.
  591.      */
  592.   if (S_DATA(name)->has_holes != Cnil)
  593.     bzero(x->str.str_self,size);
  594.   {unsigned char *s_type;
  595.    unsigned short *s_pos;
  596.    s_pos= (&SLOT_POS(x->str.str_def,0));
  597.    s_type = (&(SLOT_TYPE(x->str.str_def,0)));
  598.    base=base+1;
  599.    for (i = 0;  i < narg;  i++)
  600.      {object v=base[i];
  601.       switch(s_type[i]){
  602.          
  603.       case aet_object: STREF(object,x,s_pos[i])=v; break;
  604.       case aet_fix:  (STREF(int,x,s_pos[i]))=fix(v); break;
  605.       case aet_ch:  STREF(char,x,s_pos[i])=char_code(v); break;
  606.       case aet_bit:
  607.       case aet_char: STREF(char,x,s_pos[i])=fix(v); break;
  608.       case aet_sf: STREF(shortfloat,x,s_pos[i])=sf(v); break;
  609.       case aet_lf: STREF(longfloat,x,s_pos[i])=lf(v); break;
  610.       case aet_uchar: STREF(unsigned char,x,s_pos[i])=fix(v); break;
  611.       case aet_ushort: STREF(unsigned short,x,s_pos[i])=fix(v); break;
  612.       case aet_short: STREF(short,x,s_pos[i])=fix(v); break;
  613.       default:
  614.     bad_raw_type();
  615.  
  616. @s]
  617.  
  618.  
  619. ****Change:(orig (87 97 c))
  620. @s[       if ((narg = vs_top - vs_base) == 0)
  621.         too_few_arguments();
  622.     x = alloc_object(t_structure);
  623.     x->str.str_name = vs_base[0];
  624.  
  625. @s,               x->str.str_self[i] = vs_top[i];
  626.  
  627. @s|      }}
  628.    vs_top = base;
  629.    vs_base=base-1;
  630.  
  631.  }
  632.  
  633. @s]
  634.  
  635.  
  636. ****Change:(orig (99 99 a))
  637. @s[}
  638.  
  639.  
  640. @s|}
  641.  
  642. void
  643.  
  644. @s]
  645.  
  646.  
  647. ****Change:(orig (103 103 c))
  648. @s[       object x, y;
  649.     int i, j;
  650.  
  651. @s|       object x, y;
  652.     struct s_data *def;
  653.  
  654. @s]
  655.  
  656.  
  657. ****Change:(orig (105 105 c))
  658. @s[
  659.     check_arg(2);
  660.  
  661. @s|
  662.     if (vs_top-vs_base < 1) too_few_arguments();
  663.  
  664. @s]
  665.  
  666.  
  667. ****Change:(orig (107 110 c))
  668. @s[       if (type_of(x) != t_structure || x->str.str_name != vs_base[1])
  669.         FEwrong_type_argument(vs_base[1], x);
  670.     vs_base[1] = y = alloc_object(t_structure);
  671.     y->str.str_name = x->str.str_name;
  672.  
  673. @s|       check_type_structure(x);
  674.     vs_base[0] = y = alloc_object(t_structure);
  675.     def=S_DATA(y->str.str_def = x->str.str_def);
  676.  
  677. @s]
  678.  
  679.  
  680. ****Change:(orig (112 116 c))
  681. @s[       y->str.str_length = j = x->str.str_length;
  682.     y->str.str_self = (object *)alloc_relblock(sizeof(object)*j);
  683.     for (i = 0;  i < j;  i++)
  684.         y->str.str_self[i] = x->str.str_self[i];
  685.  
  686. @s,       vs_base++;
  687.  
  688. @s|       y->str.str_self = (object *)alloc_relblock(def->size);
  689.     bcopy(x->str.str_self,y->str.str_self,def->size);
  690.     vs_top=vs_base+1;
  691.  
  692. @s]
  693.  
  694.  
  695. ****Change:(orig (118 118 a))
  696. @s[}
  697.  
  698.  
  699. @s|}
  700.  
  701. void
  702. siLcopy_structure_header()
  703. {
  704.     object x, y;
  705.  
  706.     if (vs_top-vs_base < 1) too_few_arguments();
  707.     x = vs_base[0];
  708.     check_type_structure(x);
  709.     vs_base[0] = y = alloc_object(t_structure);
  710.     y->str.str_def = x->str.str_def;
  711.     y->str.str_self = x->str.str_self;
  712.     vs_top=vs_base+1;
  713. }
  714.  
  715.  
  716. void
  717.  
  718. @s]
  719.  
  720.  
  721. ****Change:(orig (122 124 c))
  722. @s[       if (type_of(vs_base[0]) != t_structure)
  723.         FEwrong_type_argument(Sstructure, vs_base[0]);
  724.     vs_base[0] = vs_base[0]->str.str_name;
  725.  
  726. @s|       check_type_structure(vs_base[0]);
  727.     vs_base[0] = S_DATA(vs_base[0]->str.str_def)->name;
  728.  
  729. @s]
  730.  
  731.  
  732. ****Change:(orig (127 127 c))
  733. @s[}
  734.  
  735. siLstructure_ref()
  736.  
  737. @s|}
  738.  
  739. #define FIND_SLOT(str,name) ((type_of(name)==t_fixnum)?fix(name): \
  740.                      structure_slot_position(str,name))
  741.  
  742. object
  743. structure_ref_new(x, name, i)
  744.      object x,name,i;
  745.  
  746. @s]
  747.  
  748.  
  749. ****Change:(orig (129 131 c))
  750. @s[       object x;
  751.     int i;
  752.     check_arg(3);
  753.  
  754. @s|  return structure_ref(x,name,FIND_SLOT(x,i));
  755. }
  756.  
  757. @s]
  758.  
  759.  
  760. ****Change:(orig (133 144 c))
  761. @s[       x = vs_base[0];
  762.     if (type_of(x) != t_structure ||
  763.         !structure_subtypep(x->str.str_name, vs_base[1]))
  764.         FEwrong_type_argument(vs_base[1], x);
  765.  
  766. @s,       vs_base[0] = x->str.str_self[i];
  767.     vs_top = vs_base+1;
  768.  
  769. @s|object
  770. structure_set_new(x, name, i, v)
  771.      object x,name,i,v;
  772. {
  773.   return structure_set(x,name,FIND_SLOT(x,i),v);
  774.  
  775. @s]
  776.  
  777.  
  778. ****Change:(orig (146 146 a))
  779. @s[}
  780.  
  781.  
  782. @s|}
  783.  
  784. void
  785. siLstructure_ref()
  786. {
  787.   check_arg(3);
  788.   vs_base[0]=structure_ref_new(vs_base[0],vs_base[1],vs_base[2]);
  789.   vs_top=vs_base+1;
  790. }
  791.  
  792. void
  793.  
  794. @s]
  795.  
  796.  
  797. ****Change:(orig (149 150 d))
  798. @s[siLstructure_set()
  799. {
  800.     object x;
  801.     int i;
  802.  
  803. @s|siLstructure_set()
  804. {
  805.  
  806. @s]
  807.  
  808.  
  809. ****Change:(orig (152 163 c))
  810. @s[
  811.     x = vs_base[0];
  812.     if (type_of(x) != t_structure ||
  813.         !structure_subtypep(x->str.str_name, vs_base[1]))
  814.  
  815. @s,       x->str.str_self[i] = vs_base[3];
  816.  
  817. @s|       structure_set_new(vs_base[0],vs_base[1],vs_base[2],vs_base[3]);
  818.  
  819. @s]
  820.  
  821.  
  822. ****Change:(orig (166 166 a))
  823. @s[       vs_base = vs_top-1;
  824. }
  825.  
  826.  
  827. @s|       vs_base = vs_top-1;
  828. }
  829.  
  830. void
  831.  
  832. @s]
  833.  
  834.  
  835. ****Change:(orig (228 228 c))
  836. @s[init_structure_function()
  837.  
  838. @s|void
  839. siLmake_s_data_structure()
  840. {object x,y,raw,*base;
  841.  int i;
  842.  check_arg(5);
  843.  x=vs_base[0];
  844.  base=vs_base;
  845.  raw=vs_base[1];
  846.  y=alloc_object(t_structure);
  847.  y->str.str_def=y;
  848.  y->str.str_self = (object *)( x->v.v_self);
  849.  S_DATA(y)->name  =siLs_data;
  850.  S_DATA(y)->length=(raw->v.v_dim);
  851.  S_DATA(y)->raw   =raw;
  852.  for(i=3; i<raw->v.v_dim; i++)
  853.    y->str.str_self[i]=Cnil;
  854.  S_DATA(y)->slot_position=base[2];
  855.  S_DATA(y)->slot_descriptions=base[3];
  856.  S_DATA(y)->staticp=base[4];
  857.  S_DATA(y)->size = (raw->v.v_dim)*sizeof(object);
  858.  vs_base[0]=y;
  859.  vs_top=vs_base+1;
  860. }
  861.  
  862. object siSstructure_init,siSstructure_init_named;
  863. object siSname,siSdefault_init;
  864. object siSraw,siSslot_position,siSsize,siSstaticp,siSslot_descriptions;
  865.  
  866. static object
  867. slot_value(str,name)
  868.      object str,name;
  869.  
  870. @s]
  871.  
  872.  
  873. ****Change:(orig (230 237 c))
  874. @s[       siSstructure_print_function
  875.     = make_si_ordinary("STRUCTURE-PRINT-FUNCTION");
  876.     enter_mark_origin(&siSstructure_print_function);
  877.     siSstructure_slot_descriptions
  878.  
  879. @s,       enter_mark_origin(&siSstructure_include);
  880.  
  881. @s| top:
  882.   if(type_of(str)==t_structure)
  883.     return structure_ref_new(str,str->str.str_def,name);
  884.   if(str->c.c_car==siSstructure_init_named)
  885.     {object new=get(str->c.c_cdr,siLs_data);
  886.      str->c.c_car=siSstructure_init;
  887.      str->c.c_cdr=(type_of(new)==t_structure)?new:cdr(new);}
  888.   if(siSstructure_init!=car(str))
  889.     FEerror("Illegal call to SI:MAKE-STRUCTURES 1",0);
  890.   {object key=intern(coerce_to_string(name),keyword_package);
  891.    object value=getf(cdddr(str),key,NULL);
  892.    if(value!=NULL)
  893.      return value;
  894.    else
  895.      {object slots;
  896.       if(str==caddr(str)&&name==siSslot_descriptions)
  897.     FEerror("Illegal call to SI:MAKE-STRUCTURES 2",0);
  898.       slots=slot_value(caddr(str),siSslot_descriptions);
  899.       for(;!endp(slots);slots=cdr(slots))
  900.     if(name==slot_value(car(slots),siSname))
  901.       {object result,form=slot_value(car(slots),siSdefault_init);
  902.        object *old_vs_base=vs_base,*old_vs_top=vs_top;
  903.        vs_base=vs_top;vs_push(form);Leval();result=vs_base[0];
  904.        vs_base=old_vs_base; vs_top=old_vs_top;
  905.        return result;}
  906.       FEerror("Illegal call to SI:MAKE-STRUCTURES 3",0);}}
  907.   return Cnil;
  908. }
  909.  
  910. @s]
  911.  
  912.  
  913. ****Change:(orig (238 238 a))
  914. @s[
  915.  
  916. @s|
  917. int 
  918. structure_slot_position(str,name)
  919.      object str,name;
  920. {
  921.   if(type_of(name)==t_fixnum)
  922.     return fix(name);
  923.   else
  924.     {object slotd_list;
  925.      int pos;
  926.      check_type_structure(str);
  927.      slotd_list=S_DATA(str->str.str_def)->slot_descriptions;
  928.      for(pos=0; type_of(slotd_list)==t_cons; pos++,slotd_list=cdr(slotd_list))
  929.        {object slotd=car(slotd_list);
  930.     if(name==((type_of(slotd)==t_structure)?
  931.           slotd->str.str_self[0]:slot_value(slotd,siSname)))
  932.       return pos;}
  933.      FEerror("Slot ~S not found in structure ~S",2,name,str);
  934.      return 0;}  
  935. }
  936.  
  937. static object
  938. make_structures_internal(value)
  939.      object value;
  940. {
  941.   object str,def;
  942.   int def_index,i,ind;
  943.  
  944.   switch(type_of(value))
  945.     {case t_cons:
  946.        if(value->c.c_car==siSstructure_init_named)
  947.      {object new=get(value->c.c_cdr,siLs_data);
  948.       value->c.c_car=siSstructure_init;
  949.       value->c.c_cdr=(type_of(new)==t_structure)?new:cdr(new);}
  950.        if(car(value)!=siSstructure_init)
  951.      {value->c.c_car=make_structures_internal(value->c.c_car);
  952.       value->c.c_cdr=make_structures_internal(value->c.c_cdr);
  953.       break;}
  954.        if(type_of(cadr(value))==t_structure)
  955.      {value=value->c.c_cdr->c.c_car;
  956.       break;}
  957.        {object def=caddr(value),plist=cdddr(value),result;
  958.     object slots,slots_tail;
  959.     int size,staticp,len,i;
  960.     if(def!=value)def=make_structures_internal(def);
  961.     result=alloc_object(t_structure);
  962.     result->str.str_def=(def==value)?result:def;
  963.     result->str.str_self=NULL;
  964.     value->c.c_cdr->c.c_car=result;
  965.     size=fixint(slot_value(def,siSsize));
  966.     staticp=Cnil!=slot_value(def,siSstaticp);
  967.     slots=slot_value(def,siSslot_descriptions);
  968.     len=length(slots);
  969.     result->str.str_self=(object *)(staticp?alloc_contblock(size):
  970.                                         alloc_relblock(size));
  971.     bzero(result->str.str_self,size);
  972.     if(def==value)
  973.       {S_DATA(result)->raw=slot_value(def,siSraw);
  974.        S_DATA(result)->slot_position=slot_value(def,siSslot_position);}
  975.     for(i=0,slots_tail=slots; i<len; i++,slots_tail=cdr(slots_tail))
  976.       {object svalue=slot_value(value,slot_value(car(slots_tail),siSname));
  977.        structure_set(result,result->str.str_def,i,svalue);}
  978.     for(i=0,slots_tail=slots; i<len; i++,slots_tail=cdr(slots_tail))
  979.       {object svalue=structure_ref(result,result->str.str_def,i);
  980.        svalue=make_structures_internal(svalue);
  981.        structure_set(result,result->str.str_def,i,svalue);}
  982.     value=result;
  983.     break;}
  984.      case t_vector:
  985.        if ((enum aelttype)value->v.v_elttype == aet_object)
  986.      {int i,len=value->v.v_dim;
  987.       for(i=0; i<len; i++)
  988.         value->v.v_self[i]=make_structures_internal(value->v.v_self[i]);}
  989.        break;
  990.      case t_symbol:
  991.        {object plist=value->s.s_plist,next;
  992.     for(;!endp(plist);plist=cddr(plist))
  993.       {next=plist->c.c_cdr;
  994.        if(plist->c.c_car==siLs_data&&
  995.           type_of(next->c.c_car)==t_cons)
  996.          next->c.c_car=make_structures_internal(next->c.c_car);}
  997.     break;}}
  998.   return value;   
  999. }
  1000.  
  1001. void
  1002. siLmake_structures()
  1003. {
  1004.   check_arg(1);
  1005.   vs_base[0]=make_structures_internal(vs_base[0]);
  1006. }
  1007.  
  1008. void
  1009. siLstructure_def()
  1010. {check_arg(1);
  1011.  check_type_structure(vs_base[0]);
  1012.   vs_base[0]=vs_base[0]->str.str_def;
  1013. }
  1014.  
  1015. short aet_sizes [] = {
  1016. sizeof(object),  /* aet_object  t  */
  1017. sizeof(char),  /* aet_ch  string-char  */
  1018. sizeof(char),  /* aet_bit  bit  */
  1019. sizeof(fixnum),  /* aet_fix  fixnum  */
  1020. sizeof(float),  /* aet_sf  short-float  */
  1021. sizeof(double),  /* aet_lf  long-float  */
  1022. sizeof(char),  /* aet_char  signed char */
  1023. sizeof(char),  /* aet_uchar  unsigned char */
  1024. sizeof(short),  /* aet_short  signed short */
  1025. sizeof(short)  /* aet_ushort  unsigned short   */
  1026. };
  1027.  
  1028.   
  1029.  
  1030.  
  1031.  
  1032. void
  1033. siLsize_of() 
  1034. { object x= vs_base[0];
  1035.   int i;
  1036.   i= aet_sizes[get_aelttype(x)];
  1037.   vs_base[0]=make_fixnum(i);
  1038. }
  1039.   
  1040. void
  1041. siLaet_type()
  1042. {vs_base[0]=make_fixnum(get_aelttype(vs_base[0]));}
  1043.  
  1044.  
  1045. /* Return N such that something of type ARG can be aligned on
  1046.    an address which is a multiple of N */
  1047.  
  1048.  
  1049. void
  1050. siLalignment()
  1051. {struct {double x; int y; double z;
  1052.      float x1; int y1; float z1;}
  1053.  joe;
  1054.  joe.z=3.0;
  1055.  
  1056.  if (vs_base[0]==Slong_float)
  1057.    {vs_base[0]=make_fixnum((int)&joe.z- (int)&joe.y); return;}
  1058.  else
  1059.    if (vs_base[0]==Sshort_float)
  1060.      {vs_base[0]=make_fixnum((int)&(joe.z1)-(int)&(joe.y1)); return;}
  1061.    else
  1062.      {siLsize_of();}
  1063. }
  1064.    
  1065. void
  1066. swap_structure_contents(str1,str2)
  1067.    object str1,str2;
  1068. {
  1069.   object def1,*self1;
  1070.   check_type_structure(str1);
  1071.   check_type_structure(str2);
  1072.   def1=str1->str.str_def;
  1073.   self1=str1->str.str_self;
  1074.   str1->str.str_def=str2->str.str_def;
  1075.   str1->str.str_self=str2->str.str_self;
  1076.   str2->str.str_def=def1;
  1077.   str2->str.str_self=self1;
  1078. }
  1079.  
  1080. void
  1081. siLswap_structure_contents()
  1082. {
  1083.   check_arg(2);
  1084.   swap_structure_contents(vs_base[0],vs_base[1]);
  1085.   vs_base[0]=Cnil;
  1086.   vs_top=vs_base+1;
  1087. }
  1088.  
  1089. void
  1090. siLset_structure_def()
  1091. {check_arg(2);
  1092.  check_type_structure(vs_base[0]);
  1093.  check_type_structure(vs_base[1]);
  1094.  vs_base[0]->str.str_def=vs_base[1];
  1095.  vs_base[0]=vs_base[1];
  1096.  vs_top=vs_base+1;
  1097. }
  1098.  
  1099. init_structure_function()
  1100. {
  1101.         siLs_data=make_si_ordinary("S-DATA");
  1102.     siSstructure_init=make_si_ordinary("STRUCTURE-INIT");
  1103.     siSstructure_init_named=make_si_ordinary("STRUCTURE-INIT-NAMED");
  1104.     siSname=make_si_ordinary("NAME");
  1105.     siSdefault_init=make_si_ordinary("DEFAULT-INIT");
  1106.     siSraw=make_si_ordinary("RAW");
  1107.     siSslot_position=make_si_ordinary("SLOT-POSITION");
  1108.     siSsize=make_si_ordinary("SIZE");
  1109.     siSstaticp=make_si_ordinary("STATICP");
  1110.     siSslot_descriptions=make_si_ordinary("SLOT-DESCRIPTIONS");
  1111.  
  1112. @s]
  1113.  
  1114.  
  1115. ****Change:(orig (239 239 a))
  1116. @s[       make_si_function("MAKE-STRUCTURE", siLmake_structure);
  1117.  
  1118. @s|       make_si_function("MAKE-STRUCTURE", siLmake_structure);
  1119.     make_si_function("MAKE-S-DATA-STRUCTURE",siLmake_s_data_structure);
  1120.  
  1121. @s]
  1122.  
  1123.  
  1124. ****Change:(orig (240 240 a))
  1125. @s[       make_si_function("COPY-STRUCTURE", siLcopy_structure);
  1126.  
  1127. @s|       make_si_function("COPY-STRUCTURE", siLcopy_structure);
  1128.     make_si_function("COPY-STRUCTURE-HEADER", siLcopy_structure_header);
  1129.  
  1130. @s]
  1131.  
  1132.  
  1133. ****Change:(orig (242 242 a))
  1134. @s[       make_si_function("STRUCTURE-REF", siLstructure_ref);
  1135.  
  1136. @s|       make_si_function("STRUCTURE-REF", siLstructure_ref);
  1137.     make_si_function("STRUCTURE-DEF", siLstructure_def);
  1138.     make_si_function("STRUCTURE-REF1", siLstructure_ref1);
  1139.     make_si_function("STRUCTURE-SET1", siLstructure_set1);
  1140.  
  1141. @s]
  1142.  
  1143.  
  1144. ****Change:(orig (245 245 c))
  1145. @s[       make_si_function("STRUCTUREP", siLstructurep);
  1146.  
  1147.  
  1148. @s|       make_si_function("STRUCTUREP", siLstructurep);
  1149.     make_si_function("SIZE-OF", siLsize_of);
  1150.     make_si_function("ALIGNMENT",siLalignment);
  1151.     make_si_function("STRUCTURE-SUBTYPE-P",siLstructure_subtype_p);
  1152.  
  1153. @s]
  1154.  
  1155.  
  1156. ****Change:(orig (247 247 a))
  1157. @s[       make_si_function("LIST-NTH", siLlist_nth);
  1158.  
  1159. @s|       make_si_function("LIST-NTH", siLlist_nth);
  1160.     make_si_function("AET-TYPE",siLaet_type);
  1161.     make_si_function("SWAP-STRUCTURE-CONTENTS",siLswap_structure_contents);
  1162.     make_si_function("SET-STRUCTURE-DEF", siLset_structure_def);
  1163.     make_si_function("MAKE-STRUCTURES", siLmake_structures);
  1164.  
  1165.  
  1166. @s]
  1167.  
  1168. ==============================================================================
  1169. ============================== V/lsp/defstruct.lsp =============================
  1170. Changes file for /kcl/lsp/defstruct.lsp
  1171. Usage \n@s[Original text\n@s|Replacement Text\n@s]
  1172. See the file rascal.ics.utexas.edu:/usr2/ftp/merge.c
  1173. for a program to merge change files.  Anything not between
  1174.  "\n@s[" and  "\n@s]" is a simply a comment.
  1175. This file was constructed using emacs and  merge.el
  1176.  by (Bill Schelter)  wfs@carl.ma.utexas.edu 
  1177.  
  1178.  
  1179. ****Change:(orig (20 71 c))
  1180. @s[(defun make-access-function (name conc-name type named
  1181.                              slot-name default-init slot-type read-only
  1182.                              offset)
  1183.   (declare (ignore named default-init slot-type))
  1184.  
  1185. @s,          ((error "~S is an illegal structure type." type)))))
  1186.  
  1187. @s|(defvar *accessors* (make-array 10 :adjustable t))
  1188. (defvar *list-accessors* (make-array 2 :adjustable t))
  1189. (defvar *vector-accessors* (make-array 2 :adjustable t))
  1190.  
  1191. @s]
  1192.  
  1193.  
  1194. ****Change:(orig (72 72 a))
  1195. @s[
  1196.  
  1197. @s|
  1198. (or (fboundp 'record-fn) (setf (symbol-function 'record-fn)
  1199.                        #'(lambda (&rest l) l nil)))
  1200.  
  1201. @s]
  1202.  
  1203.  
  1204. ****Change:(orig (73 73 a))
  1205. @s[
  1206.  
  1207. @s|
  1208. (defun boot-slot-value (str name)
  1209.   (if (structurep str)
  1210.       (structure-ref str (structure-def str) name)
  1211.       (getf (cdddr str) (intern (string name) :keyword))))
  1212.  
  1213. (defun boot-set-slot-value (str name new-value)
  1214.   (if (structurep str)
  1215.       (structure-set str (structure-def str) name new-value)
  1216.       (setf (getf (cdddr str) (intern (string name) :keyword)) new-value)))
  1217.  
  1218. (defun boot-subtypep (type1 type2)
  1219.   (or (eq type1 type2)
  1220.       (let* ((s-data (get type1 's-data))
  1221.          (include (boot-s-data-name (boot-slot-value s-data 'includes))))
  1222.     (boot-subtypep include type2))))
  1223.  
  1224. (defun make-slot-boot (&rest args)
  1225.   (if (get 's-data 's-data)
  1226.       (apply #'make-slot args)
  1227.       (list* 'structure-init
  1228.          nil
  1229.          '(structure-init-named . slot)
  1230.          args)))
  1231.  
  1232. (defun make-s-data-boot (&rest args)
  1233.   (if (get 's-data 's-data)
  1234.       (apply #'make-s-data args)
  1235.       (list* 'structure-init
  1236.          nil
  1237.          '(structure-init-named . s-data)
  1238.          args)))
  1239.  
  1240. (defun make-boot-accessor (slot accessor)
  1241.   (setf (symbol-function accessor) 
  1242.     #'(lambda (object)
  1243.         (boot-slot-value object slot)))
  1244.   (let ((writer (intern (format nil "SET ~A" accessor))))
  1245.     (setf (symbol-function writer)
  1246.       #'(lambda (object value)
  1247.           (boot-set-slot-value object slot value)))
  1248.     (eval `(defsetf ,accessor ,writer))))
  1249.  
  1250. (defmacro defstructboot (name &rest slots)
  1251.   (let ((conc-name (if (listp name)
  1252.                (string (second (assoc :conc-name (cdr name))))
  1253.                (format nil "~A-" name))))
  1254.     `(progn
  1255.        ,@(mapcar #'(lambda (slot)
  1256.              (let ((fname (intern (format nil "~A~A" conc-name slot))))
  1257.                `(make-boot-accessor ',slot ',fname)))
  1258.              slots))))
  1259.  
  1260. (defstructboot (slot (:conc-name boot-slot-))
  1261.   name default-init type read-only offset accessor-name type-changed)
  1262.  
  1263. (defstructboot (s-data-internal (:conc-name boot-s-data-))
  1264.   name length raw included includes staticp print-function
  1265.   slot-descriptions slot-position size has-holes)
  1266.  
  1267. (defstructboot (basic-wrapper (:conc-name boot-wrapper-))
  1268.   cache-number-vector state class)
  1269.  
  1270. (defstructboot (s-data (:conc-name boot-s-data-))
  1271.   frozen documentation constructors offset
  1272.   named type conc-name)
  1273.  
  1274. (defun make-access-function (name conc-name type named include no-fun slot)
  1275.   (declare (ignore named))
  1276.   
  1277.   (let* ((slot-name (boot-slot-name slot))
  1278.      (slot-type (boot-slot-type slot))
  1279.      (read-only (boot-slot-read-only slot))
  1280.      (offset (boot-slot-offset slot))
  1281.      (access-function
  1282.       (intern (si:string-concatenate (string conc-name)
  1283.                                  (string slot-name))))
  1284.     accsrs dont-overwrite)
  1285.     (unless (boot-slot-accessor-name slot)
  1286.       (setf (boot-slot-accessor-name slot) access-function))
  1287.     (ecase type
  1288.       ((nil)
  1289.        (setf accsrs *accessors*))
  1290.       (list
  1291.     (setf accsrs *list-accessors*))
  1292.       (vector
  1293.     (setf accsrs *vector-accessors*)))
  1294.     (or (> (length  accsrs) offset)
  1295.     (adjust-array accsrs (+ offset 10)))
  1296.     (unless
  1297.      dont-overwrite
  1298.      (record-fn access-function 'defun '(t) slot-type)
  1299.      (or no-fun
  1300.      (and (fboundp access-function)
  1301.           (eq (aref accsrs offset) (symbol-function access-function)))
  1302.      (setf (symbol-function access-function)
  1303.        (or (aref accsrs offset)
  1304.            (setf (aref accsrs offset)
  1305.              (cond  ((eq accsrs *accessors*)
  1306.                         #'(lambda (x)
  1307.                             (or (structurep x)
  1308.                                 (error "~a is not a structure" x))
  1309.                             (structure-ref1 x offset)))
  1310.                        ((eq accsrs *list-accessors*)
  1311.                         #'(lambda(x)
  1312.                             (si:list-nth offset x)))
  1313.                        ((eq accsrs *vector-accessors*)
  1314.                         #'(lambda(x)
  1315.                             (aref x offset)))))))))
  1316.     (cond (read-only
  1317.         (remprop access-function 'structure-access)
  1318.         (setf (get access-function 'struct-read-only) t))
  1319.       (t (remprop access-function 'setf-update-fn)
  1320.          (remprop access-function 'setf-lambda)
  1321.          (remprop access-function 'setf-documentation)
  1322.          (let ((tem (get access-function 'structure-access)))
  1323.            (cond ((and (consp tem) include
  1324.                    (if (consp (get include 's-data))
  1325.                        (boot-subtypep include (car tem))
  1326.                        (subtypep include (car tem)))
  1327.                    (eql (cdr tem) offset))
  1328.               ;; don't change overwrite accessor of subtype.
  1329.               (setq dont-overwrite t)
  1330.               )
  1331.              (t  (setf (get access-function 'structure-access)
  1332.                        (cons (if type type name) offset)))))))
  1333.     nil))
  1334.  
  1335.  
  1336. @s]
  1337.  
  1338.  
  1339. ****Change:(orig (80 89 c))
  1340. @s[                     (cond ((null x)
  1341.                             ;; If the slot-description is NIL,
  1342.                             ;;  it is in the padding of initial-offset.
  1343.                             nil)
  1344.  
  1345. @s,                           (t (car x))))
  1346.  
  1347. @s|                    (or (boot-slot-name x)
  1348.                  (and (boot-slot-default-init x)
  1349.                       ;; If the slot name is NIL,
  1350.                       ;;  it is the structure name.
  1351.                       ;;  This is for typed structures with names.
  1352.                       (list 'quote (boot-slot-default-init x)))))
  1353.  
  1354. @s]
  1355.  
  1356.  
  1357. ****Change:(orig (94 97 c))
  1358. @s[                     (cond ((null x) nil)
  1359.                            ((null (car x)) nil)
  1360.                            ((null (cadr x)) (list (car x)))
  1361.                            (t (list (list  (car x) (cadr x))))))
  1362.  
  1363. @s|                    (when (boot-slot-name x)
  1364.                (if (boot-slot-default-init x)
  1365.                    (list (list (boot-slot-name x) (boot-slot-default-init x)))
  1366.                    (list (boot-slot-name x)))))
  1367.  
  1368. @s]
  1369.  
  1370.  
  1371. ****Change:(orig (248 248 d))
  1372. @s[          ((error "~S is an illegal structure type" type)))))
  1373.  
  1374.  
  1375.  
  1376. @s|          ((error "~S is an illegal structure type" type)))))
  1377.  
  1378.  
  1379. @s]
  1380.  
  1381.  
  1382. ****Change:(orig (252 265 d))
  1383. @s[
  1384. (defun make-copier (name copier type named)
  1385.   (declare (ignore named))
  1386.   (cond ((null type)
  1387.  
  1388. @s,        ((error "~S is an illegal structure type." type))))
  1389.  
  1390.  
  1391.  
  1392. @s|
  1393. @s]
  1394.  
  1395.  
  1396. ****Change:(orig (267 275 c))
  1397. @s[  (cond ((null type)
  1398.          ;; If TYPE is NIL, the predicate searches the link
  1399.          ;;  of structure-include, until there is no included structure.
  1400.          `(defun ,predicate (x)
  1401.  
  1402. @s,                   (setq n (get n 'structure-include))))))
  1403.  
  1404. @s|  (cond ((null type))
  1405.      ; done in define-structure
  1406.  
  1407. @s]
  1408.  
  1409.  
  1410. ****Change:(orig (282 283 c))
  1411. @s[                 (> (length x) ,name-offset)
  1412.                  (eq (elt x ,name-offset) ',name))))
  1413.  
  1414. @s|                 (> (the fixnum (length x)) ,name-offset)
  1415.                  (eq (aref (the (vector t) x) ,name-offset) ',name))))
  1416.  
  1417. @s]
  1418.  
  1419.  
  1420. ****Change:(orig (294 294 a))
  1421. @s[                         ((= i 0) (and (consp y) (eq (car y) ',name)))
  1422.  
  1423. @s|                         ((= i 0) (and (consp y) (eq (car y) ',name)))
  1424.                  (declare (fixnum i))
  1425.  
  1426. @s]
  1427.  
  1428.  
  1429. ****Change:(orig (300 301 c))
  1430. @s[;;;  and returns a list of the form:
  1431. ;;;        (slot-name default-init slot-type read-only offset)
  1432.  
  1433. @s|;;;  and returns a slot.
  1434.  
  1435. @s]
  1436.  
  1437.  
  1438. ****Change:(orig (325 325 c))
  1439. @s[    (list slot-name default-init slot-type read-only offset)))
  1440.  
  1441. @s|    (make-slot-boot :name slot-name
  1442.             :default-init default-init
  1443.             :type slot-type
  1444.             :read-only read-only
  1445.             :offset offset)))
  1446.  
  1447. @s]
  1448.  
  1449.  
  1450. ****Change:(orig (335 335 c))
  1451. @s[      (let ((sds (member (caar olds) news :key #'car)))
  1452.  
  1453. @s|      (let* ((old (car olds))
  1454.          (sds (member (boot-slot-name old) news :key #'slot-name))
  1455.          (new (car sds)))
  1456.  
  1457. @s]
  1458.  
  1459.  
  1460. ****Change:(orig (337 348 c))
  1461. @s[               (when (and (null (cadddr (car sds)))
  1462.                           (cadddr (car olds)))
  1463.                      ;; If read-only is true in the old
  1464.                      ;;  and false in the new, signal an error.
  1465.  
  1466. @s,                           (car (cddddr (car olds))))
  1467.  
  1468. @s|               (when (and (null (boot-slot-read-only new))
  1469.                           (boot-slot-read-only old))
  1470.          ;; If read-only is true in the old
  1471.          ;;  and false in the new, signal an error.
  1472.          (error "~S is an illegal include slot-description."
  1473.                 new))
  1474.            ;; If
  1475.            (setf (boot-slot-type new)
  1476.              (best-array-element-type (boot-slot-type new)))
  1477.            (when (not (equal (normalize-type (or (boot-slot-type new) t))
  1478.                          (normalize-type (or (boot-slot-type old) t))))
  1479.          (error "Type mismmatch for included slot ~a" new))
  1480.            (cons (make-slot :name (boot-slot-name new)
  1481.                         :default-init (boot-slot-default-init new)
  1482.                         :type (boot-slot-type new)
  1483.                         :read-only (boot-slot-read-only new)
  1484.                         :offset (boot-slot-offset old))
  1485.  
  1486. @s]
  1487.  
  1488.  
  1489. ****Change:(orig (353 353 a))
  1490. @s[                     (overwrite-slot-descriptions news (cdr olds))))))))
  1491.  
  1492.  
  1493. @s|                     (overwrite-slot-descriptions news (cdr olds))))))))
  1494.  
  1495. (defvar *all-t-s-type* (make-array 50 :element-type 'unsigned-char :static t))
  1496.  
  1497. @s]
  1498.  
  1499.  
  1500. ****Change:(orig (355 355 c))
  1501. @s[;;; The DEFSTRUCT macro.
  1502.  
  1503. @s|(defun make-t-type (n include slot-descriptions &aux i)
  1504.   (let ((res  (make-array n :element-type 'unsigned-char :static t)))
  1505.     (when include
  1506.       (let ((tem (get include 's-data))raw)
  1507.     (or tem (error "Included structure undefined ~a" include))
  1508.     (setq raw (boot-s-data-raw tem))
  1509.     (dotimes (i (min n (length raw)))
  1510.       (setf (aref res i) (aref raw i)))))
  1511.     (dolist (v slot-descriptions)
  1512.       (setq i (boot-slot-offset v))
  1513.       (let ((type (boot-slot-type v)))
  1514.     (cond ((<= (the fixnum (alignment type)) #. (alignment t))
  1515.            (setf (aref res i) (aet-type type))))))
  1516.     (cond ((< n (length *all-t-s-type*))
  1517.        (dotimes (i n)
  1518.          (cond ((not (eql (the fixnum (aref res i)) 0))
  1519.             (return-from make-t-type res))))
  1520.        *all-t-s-type*)
  1521.       (t res))))
  1522.  
  1523. @s]
  1524.  
  1525.  
  1526. ****Change:(orig (356 356 a))
  1527. @s[
  1528.  
  1529. @s|
  1530. (defvar *standard-slot-positions*
  1531.   (let ((ar (make-array 50 :element-type 'unsigned-short
  1532.                 :static t))) 
  1533.     (dotimes (i 50)
  1534.          (declare (fixnum i))
  1535.          (setf (aref ar i)(* #. (size-of t) i)))
  1536.     ar))
  1537.  
  1538. (eval-when (compile )
  1539. (proclaim '(function round-up (fixnum fixnum ) fixnum))
  1540. )
  1541.  
  1542. (defun round-up (a b)
  1543.   (declare (fixnum a b))
  1544.   (setq a (ceiling a b))
  1545.   (the fixnum (* a b)))
  1546.  
  1547.  
  1548. (defun get-slot-pos (leng include slot-descriptions &aux type small-types
  1549.                   has-holes) 
  1550.   (declare (special *standard-slot-positions*)) include
  1551.   (dolist (v slot-descriptions)
  1552.     (when (boot-slot-name v)
  1553.       (setf type (best-array-element-type (boot-slot-type v))
  1554.         (boot-slot-type v) type)
  1555.       (let ((val (boot-slot-default-init v)))
  1556.     (unless (typep val type)
  1557.       (if (and (symbolp val)
  1558.            (constantp val))
  1559.           (setf val (symbol-value val)))
  1560.       (and (constantp val)
  1561.            (setf (boot-slot-default-init v) (coerce val type)))))
  1562.       (cond ((memq type '(signed-char unsigned-char
  1563.                   short unsigned-short
  1564.                   long-float
  1565.                   bit))
  1566.          (setq small-types t)))))
  1567.   (cond ((and (null small-types)
  1568.           (< leng (length *standard-slot-positions*))
  1569.           (list  *standard-slot-positions* (* leng #. (size-of t)) nil)))
  1570.     (t (let ((ar (make-array leng :element-type 'unsigned-short
  1571.                          :static t))
  1572.          (pos 0)(i 0)(align 0)type (next-pos 0))
  1573.          (declare (fixnum pos i align next-pos))
  1574.          ;; A default array.
  1575.            
  1576.          (dolist (v slot-descriptions)
  1577.            (setq type (boot-slot-type v))
  1578.            (setq align (alignment type))
  1579.            (unless (<= align #. (alignment t))
  1580.          (setq type t)
  1581.          (setf (boot-slot-type v) t)
  1582.          (setq align #. (alignment t))
  1583.          (setf (boot-slot-type-changed v) t))
  1584.            (setq next-pos (round-up pos align))      
  1585.            (or (eql pos next-pos) (setq has-holes t))
  1586.            (setq pos next-pos)
  1587.            (setf (aref ar i) pos)
  1588.            (incf pos (size-of type))
  1589.            (incf i))
  1590.          (list ar (round-up pos (size-of t)) has-holes)
  1591.          ))))
  1592.  
  1593.  
  1594. (defun define-structure (name conc-name type named slot-descriptions copier
  1595.                       static include print-function constructors
  1596.                       offset predicate &optional documentation no-funs
  1597.                       &aux leng)
  1598.   (and (consp type) (eq (car type) 'vector)(setq type 'vector))
  1599.   (setq leng (length slot-descriptions))
  1600.   (setq slot-descriptions 
  1601.     (mapcar #'(lambda (info)
  1602.             (make-slot-boot :name (first info)
  1603.                             :default-init (second info)
  1604.                             :type (third info)
  1605.                             :read-only (fourth info)
  1606.                             :offset (fifth info)
  1607.                             :accessor-name (sixth info)
  1608.                             :type-changed (seventh info)))
  1609.         slot-descriptions))
  1610.   (dolist (x slot-descriptions)
  1611.     (when (boot-slot-name x)
  1612.       (make-access-function name conc-name type named include no-funs x)))
  1613.   (when (and copier (not no-funs))
  1614.     (setf (symbol-function copier)
  1615.       (ecase type
  1616.         ((nil) #'si::copy-structure)
  1617.         (list #'copy-list)
  1618.         (vector #'copy-seq))))
  1619.   (let ((include-str (and include (get include 's-data))))
  1620.     (when (and (eq include 's-data-internal)
  1621.            (not (eq name 'basic-wrapper)))
  1622.       (error "only ~s can include ~s" 'basic-wrapper 's-data-internal))
  1623.     (when include-str
  1624.       (cond ((and (not (consp include-str))
  1625.           (s-data-frozen include-str)
  1626.           (or (not (s-data-included include-str))
  1627.               (not (let ((te (get name 's-data)))
  1628.                      (and te
  1629.                           (eq (s-data-includes te)
  1630.                               include-str))))))
  1631.          (warn " ~a was frozen but now included"
  1632.            include)))
  1633.       (let ((old-included (boot-slot-value include-str 'included)))
  1634.     (unless (member name old-included)
  1635.       (boot-set-slot-value include-str 'included (cons name old-included)))))
  1636.     (let* ((tem (get name 's-data))
  1637.        (g-s-p (and (null type)
  1638.                (get-slot-pos leng include slot-descriptions)))
  1639.        (slot-position (car g-s-p))
  1640.        (size (if g-s-p (cadr g-s-p) 0))
  1641.        (has-holes (caddr g-s-p))
  1642.        (def (make-s-data-boot :name name
  1643.                           :length leng
  1644.                           :raw
  1645.                           (and (null type)
  1646.                                (make-t-type leng include 
  1647.                                             slot-descriptions))
  1648.                           :slot-position slot-position
  1649.                           :size size
  1650.                           :has-holes has-holes
  1651.                           :staticp static
  1652.                           :includes include-str
  1653.                           :print-function print-function
  1654.                           :slot-descriptions slot-descriptions
  1655.                           :constructors constructors
  1656.                           :offset offset
  1657.                           :type type
  1658.                           :named named
  1659.                           :documentation documentation
  1660.                           :conc-name conc-name)))
  1661.       (check-s-data tem def name)
  1662.       (when (and (consp def) (eq name 's-data))
  1663.     (make-structures def))))
  1664.   (when documentation
  1665.     (setf (get name 'structure-documentation)
  1666.       documentation))
  1667.   (when (and  (null type)  predicate)
  1668.     (record-fn predicate 'defun '(t) t)
  1669.     (or no-funs
  1670.     (setf (symbol-function predicate)
  1671.           #'(lambda (x)
  1672.           (si::structure-subtype-p x name))))
  1673.     (setf (get predicate 'compiler::co1)
  1674.       'compiler::co1structure-predicate)
  1675.     (setf (get predicate 'struct-predicate) name))
  1676.   nil)
  1677.  
  1678. (defun check-s-data (old new name)
  1679.   (unless (and old (member name '(slot s-data-internal basic-wrapper s-data)))
  1680.     (when (and old (eq (structure-def old) (get 's-data 's-data)))
  1681.       (boot-set-slot-value new 'included (boot-slot-value old 'included))
  1682.       (boot-set-slot-value new 'frozen (boot-slot-value old 'frozen)))
  1683.     (unless (and old
  1684.          (eq (structure-def old) (get 's-data 's-data))
  1685.          (let ((new-cnv (boot-slot-value new 'cache-number-vector))
  1686.                (old-cnv (boot-slot-value old 'cache-number-vector)))
  1687.            (boot-set-slot-value new 'cache-number-vector old-cnv)
  1688.            (prog1 (equalp new old)
  1689.              (boot-set-slot-value new 'cache-number-vector new-cnv))))
  1690.       (when old
  1691.     (warn "structure ~a is changing" name)
  1692.     (when (eq (structure-def old) (get 's-data 's-data))
  1693.       (boot-set-slot-value old 'state (list ':obsolete new))))
  1694.       (setf (get name 's-data) new))))
  1695.  
  1696.  
  1697. @s]
  1698.  
  1699.  
  1700. ****Change:(orig (364 364 c))
  1701. @s[        predicate predicate-specified
  1702.         include
  1703.  
  1704. @s|        predicate predicate-specified
  1705.         include include-s-data
  1706.  
  1707. @s]
  1708.  
  1709.  
  1710. ****Change:(orig (367 367 c))
  1711. @s[        offset name-offset
  1712.         documentation)
  1713.  
  1714. @s|        offset name-offset
  1715.         documentation
  1716.     static)
  1717.  
  1718. @s]
  1719.  
  1720.  
  1721. ****Change:(orig (370 370 c))
  1722. @s[          ;; The defstruct options are supplied.
  1723.  
  1724. @s|         ;; The defstruct options are supplied.
  1725.  
  1726. @s]
  1727.  
  1728.  
  1729. ****Change:(orig (390 425 c))
  1730. @s[      (cond ((and (consp (car os)) (not (endp (cdar os))))
  1731.              (setq o (caar os) v (cadar os))
  1732.              (case o
  1733.                (:conc-name
  1734.  
  1735. @s,               (t (error "~S is an illegal defstruct option." o))))))
  1736.  
  1737. @s|       (cond ((and (consp (car os)) (not (endp (cdar os))))
  1738.            (setq o (caar os) v (cadar os))
  1739.            (case o
  1740.          (:conc-name
  1741.            (if (null v)
  1742.                (setq conc-name "")
  1743.              (setq conc-name v)))
  1744.          (:constructor
  1745.            (if (null v)
  1746.                (setq no-constructor t)
  1747.              (if (endp (cddar os))
  1748.                  (setq constructors (cons v constructors))
  1749.                (setq constructors (cons (cdar os) constructors)))))
  1750.          (:copier (setq copier v))
  1751.          (:static (setq static v))
  1752.          (:predicate
  1753.            (setq predicate v)
  1754.            (setq predicate-specified t))
  1755.          (:include
  1756.            (setq include (cdar os))
  1757.            (unless (setq include-s-data (get v 's-data))
  1758.                    (error "~S is an illegal included structure." v)))
  1759.          (:print-function
  1760.           (and (consp v) (eq (car v) 'function)
  1761.                (setq v (second v)))
  1762.           (setq print-function v))
  1763.          (:type (setq type v))
  1764.          (:initial-offset (setq initial-offset v))
  1765.          (t (error "~S is an illegal defstruct option." o))))
  1766.           (t
  1767.         (if (consp (car os))
  1768.             (setq o (caar os))
  1769.           (setq o (car os)))
  1770.         (case o
  1771.           (:constructor
  1772.             (setq constructors
  1773.                   (cons default-constructor constructors)))
  1774.           ((:conc-name :copier :predicate :print-function))
  1775.           (:named (setq named t))
  1776.           (t (error "~S is an illegal defstruct option." o))))))
  1777.  
  1778. @s]
  1779.  
  1780.  
  1781. ****Change:(orig (426 426 a))
  1782. @s[
  1783.  
  1784. @s|
  1785.     (setq conc-name (intern (string conc-name)))
  1786.  
  1787.     (and include-s-data (not print-function)
  1788.      (setq print-function (boot-s-data-print-function include-s-data)))
  1789.  
  1790.  
  1791. @s]
  1792.  
  1793.  
  1794. ****Change:(orig (434 435 c))
  1795. @s[    (when include
  1796.           (unless (equal type (get (car include) 'structure-type))
  1797.  
  1798. @s|    (when include-s-data
  1799.           (unless (equal type (boot-s-data-type include-s-data))
  1800.  
  1801. @s]
  1802.  
  1803.  
  1804. ****Change:(orig (442 443 c))
  1805. @s[          (t
  1806.            (setq offset (get (car include) 'structure-offset))))
  1807.  
  1808. @s|          (t 
  1809.         (setq offset (boot-s-data-offset include-s-data))))
  1810.  
  1811. @s]
  1812.  
  1813.  
  1814. ****Change:(orig (457 458 c))
  1815. @s[      (setq sds (cons (parse-slot-description (car ds) offset) sds))
  1816.       (setq offset (1+ offset)))
  1817.  
  1818. @s|       (setq sds (cons (parse-slot-description (car ds) offset) sds))
  1819.     (setq offset (1+ offset)))
  1820.  
  1821. @s]
  1822.  
  1823.  
  1824. ****Change:(orig (464 464 c))
  1825. @s[                (cons (list nil name) slot-descriptions)))
  1826.  
  1827. @s|                (cons (make-slot :default-init name) slot-descriptions)))
  1828.  
  1829. @s]
  1830.  
  1831.  
  1832. ****Change:(orig (469 469 c))
  1833. @s[                (append (make-list initial-offset) slot-descriptions)))
  1834.  
  1835. @s|                (append (mapcar #'make-named-slot (make-list initial-offset))
  1836.                 slot-descriptions)))
  1837.  
  1838. @s]
  1839.  
  1840.  
  1841. ****Change:(orig (473 486 c))
  1842. @s[    (cond ((null include))
  1843.           ((endp (cdr include))
  1844.            (setq slot-descriptions
  1845.                  (append (get (car include) 'structure-slot-descriptions)
  1846.  
  1847. @s,                         slot-descriptions))))
  1848.  
  1849. @s|    (let ((include-slot-descriptions 
  1850.        (and include
  1851.         (boot-s-data-slot-descriptions include-s-data))))
  1852.       (cond ((null include))
  1853.         ((endp (cdr include))
  1854.          (setq slot-descriptions
  1855.            (append include-slot-descriptions
  1856.                    slot-descriptions)))
  1857.         (t
  1858.          (setq slot-descriptions
  1859.            (append (overwrite-slot-descriptions
  1860.                     (mapcar #'(lambda (sd)
  1861.                                 (parse-slot-description sd 0))
  1862.                             (cdr include))
  1863.                     include-slot-descriptions)
  1864.                    slot-descriptions)))))
  1865.  
  1866. @s]
  1867.  
  1868.  
  1869. ****Change:(orig (489 492 c))
  1870. @s[           ;; If a constructor option is NIL,
  1871.            ;;  no constructor should have been specified.
  1872.            (when constructors
  1873.                  (error "Contradictory constructor options.")))
  1874.  
  1875. @s|           ;; If a constructor option is NIL,
  1876.         ;;  no constructor should have been specified.
  1877.         (when constructors
  1878.           (error "Contradictory constructor options.")))
  1879.  
  1880. @s]
  1881.  
  1882.  
  1883. ****Change:(orig (494 495 c))
  1884. @s[           ;; If no constructor is specified,
  1885.            ;;  the default-constructor is made.
  1886.  
  1887. @s|          ;; If no constructor is specified,
  1888.        ;;  the default-constructor is made.
  1889.  
  1890. @s]
  1891.  
  1892.  
  1893. ****Change:(orig (497 497 a))
  1894. @s[           (setq constructors (list default-constructor))))
  1895.  
  1896.  
  1897. @s|           (setq constructors (list default-constructor))))
  1898.  
  1899.     ;; We need a default constructor for the sharp-s-reader
  1900.     (or (member t (mapcar 'symbolp  constructors))
  1901.     (push (intern (string-concatenate "__si::" default-constructor))
  1902.               constructors))
  1903.  
  1904.  
  1905. @s]
  1906.  
  1907.  
  1908. ****Change:(orig (509 509 c))
  1909. @s[          (error "An print function is supplied to a typed structure."))
  1910.  
  1911. @s|          (error "A print function is supplied to a typed structure."))
  1912.     
  1913.     `(progn
  1914.        (define-structure ',name  ',conc-name ',type ',named
  1915.                  ',(mapcar #'(lambda (slotd)
  1916.                                (list (boot-slot-name slotd)
  1917.                                      (boot-slot-default-init slotd)
  1918.                                      (boot-slot-type slotd)
  1919.                                      (boot-slot-read-only slotd)
  1920.                                      (boot-slot-offset slotd)
  1921.                                      (boot-slot-accessor-name slotd)
  1922.                                      (boot-slot-type-changed slotd)))
  1923.                            slot-descriptions)
  1924.                  ',copier ',static ',include ',print-function ',constructors 
  1925.                  ',offset ',predicate ',documentation)
  1926.  
  1927. @s]
  1928.  
  1929.  
  1930. ****Change:(orig (511 542 c))
  1931. @s[    `(progn (si:putprop ',name
  1932.                         '(defstruct ,name ,@slots)
  1933.                         'defstruct-form)
  1934.             (si:putprop ',name t 'is-a-structure)
  1935.  
  1936. @s,            (si:putprop ',name ,documentation 'structure-documentation)
  1937.             ',name)))
  1938.  
  1939. @s|       ,@(mapcar #'(lambda (constructor)
  1940.              (make-constructor name constructor type named
  1941.                                slot-descriptions))
  1942.          constructors)
  1943.        ,@(if (and type predicate)
  1944.          (list (make-predicate name predicate type named
  1945.                            name-offset)))
  1946.        ',name
  1947.        )))
  1948.  
  1949. @s]
  1950.  
  1951.  
  1952. ****Change:(orig (544 544 a))
  1953. @s[
  1954.  
  1955.  
  1956. @s|
  1957.  
  1958. (eval-when (compile load eval)
  1959.  
  1960. (defconstant wrapper-cache-number-adds-ok 4)
  1961.  
  1962. (defconstant wrapper-cache-number-length
  1963.          (- (integer-length most-positive-fixnum)
  1964.         wrapper-cache-number-adds-ok))
  1965.  
  1966. (defconstant wrapper-cache-number-mask
  1967.          (1- (expt 2 wrapper-cache-number-length)))
  1968.  
  1969.  
  1970. (defvar *get-wrapper-cache-number* (make-random-state))
  1971.  
  1972. (defun get-wrapper-cache-number ()
  1973.   (let ((n 0))
  1974.     (declare (fixnum n))
  1975.     (loop
  1976.       (setq n
  1977.         (logand wrapper-cache-number-mask
  1978.             (random most-positive-fixnum *get-wrapper-cache-number*)))
  1979.       (unless (zerop n) (return n)))))
  1980.  
  1981. )
  1982.  
  1983. (eval-when (compile load eval)
  1984.  
  1985. (defconstant wrapper-cache-number-vector-length 8)
  1986.  
  1987. (deftype cache-number-vector ()
  1988.   `(simple-array fixnum (8)))
  1989.  
  1990. (defconstant wrapper-layout (make-list wrapper-cache-number-vector-length
  1991.                                :initial-element 'number))
  1992.  
  1993. )
  1994.  
  1995. (defun make-wrapper-cache-number-vector ()
  1996.   (let ((cnv (make-array #.wrapper-cache-number-vector-length
  1997.                  :element-type 'fixnum)))
  1998.     (dotimes (i #.wrapper-cache-number-vector-length)
  1999.       (setf (aref cnv i) (get-wrapper-cache-number)))
  2000.     cnv))
  2001.  
  2002. (defstruct (slot
  2003.          (:static t)
  2004.          (:constructor make-slot)
  2005.          (:constructor make-named-slot (name)))
  2006.   name
  2007.   default-init
  2008.   (type t)
  2009.   read-only
  2010.   offset
  2011.   accessor-name
  2012.   type-changed)
  2013.  
  2014. ;; All of the fields of s-data-internal must coincide with 
  2015. ;; the C structure s_data (see object.h).
  2016. (defstruct (s-data-internal
  2017.          (:conc-name s-data-)
  2018.          (:constructor nil)
  2019.          (:static t))
  2020.   ;; all of these slots are used by c code
  2021.   name                    ; a symbol
  2022.   (length 0 :type fixnum) ; length of slot-descriptions
  2023.   raw                     ; a static array of unsigned-short (enum aelttype)
  2024.   included                ; a list of the names of structures including this one
  2025.   includes                ; nil or a s-data structure
  2026.   staticp         ; t or nil
  2027.   print-function  ; nil, a symbol, or a lambda expression
  2028.   slot-descriptions       ; a list of slots
  2029.   slot-position           ; a static array of unsigned-short
  2030.   (size 0 :type fixnum) ; total size to allocate
  2031.   has-holes)              ; t or nil
  2032.  
  2033. (defstruct (basic-wrapper (:include s-data-internal)
  2034.                   (:conc-name wrapper-)
  2035.                   (:constructor nil)
  2036.                   (:static t))
  2037.   (cache-number-vector (make-wrapper-cache-number-vector))
  2038.   (state t) ;  either t or a list (state-sym new-wrapper)
  2039.   ;;           where state-sym is either :flush or :obsolete
  2040.   (class nil))
  2041.  
  2042. ;(get name 'si::s-data) ;returns one of these:
  2043. (defstruct (s-data (:include basic-wrapper)
  2044.            (:static t))
  2045.   ;; these slots are used only from lisp
  2046.   frozen          ; t or nil ; t means won't include this
  2047.   documentation 
  2048.   constructors            ; a list of either a symbol or a list symbol, arglist
  2049.   offset          ; the total number of slots and placeholders
  2050.   named                   ; t or nil
  2051.   type                    ; one of: nil, list, or vector
  2052.   conc-name)              ; an interned symbol
  2053.  
  2054. #|| 
  2055. (import '(si::wrapper-state si::wrapper-class si::basic-wrapper))
  2056.  
  2057. (defstruct (wrapper (:include basic-wrapper)
  2058.             (:print-function print-wrapper)
  2059.             (:constructor make-wrapper-internal)
  2060.             (:predicate wrapper-p)
  2061.             (:conc-name wrapper-))
  2062.   (class-slots nil :type list))
  2063.  
  2064. (defun print-wrapper (instance stream depth)
  2065.   (printing-random-thing (wrapper stream)
  2066.     (format stream "Wrapper ~S" (wrapper-class wrapper))))
  2067. ||#
  2068.  
  2069. (defun update-wrapper-state (old new same-p)
  2070.   (unless (consp old)
  2071.     (setf (wrapper-state old) 
  2072.       (list (if same-p ':flush ':obsolete) new))))
  2073.  
  2074. (defun freeze-defstruct (name)
  2075.   (let ((tem (and (symbolp name) (get name 's-data))))
  2076.     (if tem (setf (s-data-frozen tem) t))))
  2077.  
  2078.  
  2079.  
  2080. @s]
  2081.  
  2082.  
  2083. ****Change:(orig (551 553 c))
  2084. @s[  (let ((l (read stream)))
  2085.     (unless (get (car l) 'is-a-structure)
  2086.             (error "~S is not a structure." (car l)))
  2087.  
  2088. @s|  (let* ((l (prog1 (read stream t nil t)
  2089.           (if *read-suppress*
  2090.           (return-from sharp-s-reader nil))))
  2091.      (sd
  2092.        (or (get (car l) 's-data)
  2093.            
  2094.            (error "~S is not a structure." (car l)))))
  2095.     
  2096.  
  2097. @s]
  2098.  
  2099.  
  2100. ****Change:(orig (558 558 c))
  2101. @s[         (do ((cs (get (car l) 'structure-constructors) (cdr cs)))
  2102.  
  2103. @s|         (do ((cs (s-data-constructors sd) (cdr cs)))
  2104.  
  2105. @s]
  2106.  
  2107.  
  2108. ****Change:(orig (571 571 d))
  2109. @s[(set-dispatch-macro-character #\# #\S 'sharp-s-reader)
  2110.  
  2111.  
  2112.  
  2113. @s|(set-dispatch-macro-character #\# #\S 'sharp-s-reader)
  2114.  
  2115.  
  2116. @s]
  2117.  
  2118.  
  2119. ****Change:(orig (582 582 c))
  2120. @s[(defstruct person name age sex)
  2121.  
  2122. @s|(defstruct person name (age 20 :type signed-char) (eyes 2 :type signed-char)
  2123.                                                 sex)
  2124. (defstruct person name (age 20 :type signed-char) (eyes 2 :type signed-char)
  2125.                                                 sex)
  2126. (defstruct person1 name (age 20 :type fixnum)
  2127.                                                 sex)
  2128.  
  2129. @s]
  2130.  
  2131.  
  2132. ****Change:(orig (584 584 c))
  2133. @s[(defstruct (astronaut (:include person (age 45))
  2134.  
  2135. @s|(defstruct joe a (a1 0 :type (mod  30)) (a2 0 :type (mod  30))
  2136.   (a3 0 :type (mod  30)) (a4 0 :type (mod 30)) )
  2137.  
  2138. ;(defstruct person name age sex)
  2139.  
  2140. (defstruct (astronaut (:include person (age 45 :type fixnum))
  2141.  
  2142. @s]
  2143.  
  2144.  
  2145. ****Change:(orig (605 605 a))
  2146. @s[  associative
  2147.   identity)
  2148.  
  2149. @s|  associative
  2150.   identity)
  2151.  
  2152.  
  2153. @s]
  2154.  
  2155. ==============================================================================
  2156.